package com.atguigu.tingshu.user.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;

import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.interfaces.RSAPrivateKey;

@Configuration
public class TokenKeyConfig {
    @Bean
    public RSAPrivateKey rsaPrivateKey(){
        ClassPathResource classPathResource = new ClassPathResource("tingshu.jks");
        KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(classPathResource, "tingshu".toCharArray());
        KeyPair tingshu = keyStoreKeyFactory.getKeyPair("tingshu", "tingshu".toCharArray());
        RSAPrivateKey aPrivate =(RSAPrivateKey) tingshu.getPrivate();
        return aPrivate;
    }
}
